// read: tsc ./src/app.ts --outFile ./dist/app.js
// read: tsc ./src/* --outDir ./dist --watch

import EmitterEvent from "./EmitterEvent";
import EmitterTarget from "./EmitterTarget";

// read: tsc --watch  //配置json文件后
let myname: string = "字符串";

let isDone: boolean = false;
let isNum: number = 1111;

// myname = 0 // 定义为其他类型没有致命错误,但是是有隐患的
myname = `我是 ${myname}`; //重新赋值
// console.log(myname);

let myArr: Array<any> = ["1", 2, false];
let myList: number[] = [1, 2];

// 元组 Tuple
let x: [string, number] = ["1", 2];

// 枚举
enum Color {
  Red,
  Green = 1,
  Blue,
}
let c: Color = Color.Red;
//console.log(c);
let colorName: string = Color[1];
let colorName4: string = Color[2];
//console.log(colorName);
//console.log(colorName4);

let a: any = 0;
a = "速度";
//console.log(a);

let n: number | null = 1;
n = null;

let sym1 = Symbol("key");
//console.log(sym1)
let obj = {
  [sym1]: "value",
};
//console.log(obj[sym1])

// 函数
function sun(x: number, y: number) {
  return x + y;
}

let sun1 = function (x: number, y: number) {
  return x + y;
};

// (x: number, y: number) => number 定义函数类型,报错参数类型和返回值类型
let sun2: (x: number, y: number) => number = function (x: number, y: number) {
  return x + y;
};

// 接口
interface Search {
  (a: string, b: string): boolean;
}
let sun3: Search = function (a: string, b: string): boolean {
  return a === b;
};

class Animal {
  public render(): string {
    return "woshi render";
  }
  public getProps(): void {
    console.log("xxx--watch");
  }
}
class Cat extends Animal {
  // public getChild(): void {
  //   console.log("我是child");
  // }
}
// let b: Animal = new Animal()
// b.getProps b.render

// let b: Animal = new Cat()
// b.getProps b.render

let b: Cat = new Animal();
// Property 'getChild' is missing in type 'Animal' but required in type 'Cat'.
b.getProps();

// let b: Cat = new Cat()
// b.getProps; b.render; b.getChild

// var evt = new EmitterEvent('hsl')
// evt.a = 10;
// evt.addEventListener()
// console.log(evt)
var target = new EmitterTarget();
target.addEventListener("hsl", handelHsl1);
target.addEventListener("hsl", handelHsl2);


function handelHsl1(e: EmitterEvent) {
  console.log(e);
}
function handelHsl2(e: EmitterEvent) {
  (e.currentTarget as EmitterTarget).removeEventListener("hsl", handelHsl2);
  console.log(e,  '只会执行一次');
}


var evt = new EmitterEvent("hsl");
evt.aa =3
target.dispatchEvent(evt);//抛发两次
target.dispatchEvent(evt);

// 迭代器                                                         
// 对象时不能被迭代的
import './Gen'